package com.lagou.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author srh
 * @date 2020/05/04
 **/
@Controller
@RequestMapping(value = "/login")
public class LoginController {

    @RequestMapping(value = "/toLogin")
    public String login() {
        return "login";
    }

    @RequestMapping("/loginSystem")
    public String loginSystem(String username, String password, HttpSession session) {
        // 合法用户，信息写入session，同时跳转到系统主页面
        if ("admin".equals(username) && "admin".equals(password)) {
            session.setAttribute("username", username);
            return "redirect:/toResult";
        } else {
            // 非法用户返回登录页面
            return "redirect:/login/toLogin";
        }
    }

}
